﻿/*
* File:CastleEffectPool
* Author: liumeng@yoozoo.com
* Date: 2018/7/19 22:09:13
* Description:
*
*  沙盘玩家主城上的特效对象池
*
*/

using System.Collections.Generic;
using UnityEngine;

namespace Yoozoo.Mars.Got
{
    public class CastleEffectPool
    {
        private Dictionary<string,Stack<Transform>> pool;
        private string name;
        private static  CastleEffectPool _instance;

        public static  CastleEffectPool Instance
        {
            get
            {
                if (_instance == null)
                        _instance = new CastleEffectPool();
                return _instance;
            }

            set
            {
                _instance = value;
            }
        }

        public CastleEffectPool()
        {
            pool = new Dictionary<string, Stack<Transform>>();
 
        }
       
        public void RecoverItem(string name,Transform transfrom)
        {
            if (!pool.ContainsKey(name)) {
                pool.Add(name, new Stack<Transform>());
            }
            transfrom.gameObject.SetActive(false);
            pool[name].Push(transfrom);
            
        }

        public Transform GetItem(string name)
        {
           if(pool.ContainsKey(name) && pool[name].Count > 0)
            {
                var item = pool[name].Pop();
                item.gameObject.SetActive(true);
                return item;
            }
            return null;
        }

        public void ClearPool()
        {
            pool.Clear();
        }
    }
}
